import axios from "@/utils/request";
import {
    ArticleVo,
    Browse,
    Collect,
    CommentsGiveALike,
    CommentsVo,
    GiveALike,
    SecondCommentsParams
} from "@/model/home/article";
import {RequestParams} from "@/model/home/answer";

//获取一级标签列表
export function getOneSortList() {
    return axios({
        url: "article/oneSort/web/getOneSortList",
        method: "get"
    })
}

//获取文章列表
export function getArticleList(current: number, size: number) {
    return axios({
        url: `article/articles/web/getArticleList/${current}/${size}`,
        method: "get"
    })
}

//发布文章
export function saveArticle(articleVo: ArticleVo) {
    return axios({
        url: "article/articles/web/saveArticle",
        method: "post",
        data: articleVo
    })
}

//获取一级和二级标签
export function getOneAndTwoSortList() {
    return axios({
        url: "article/oneSort/web/getOneAndTwoSortList",
        method: "get"
    })
}

//用户点赞
export function saveUserGiveALike(giveALike: GiveALike) {
    return axios({
        url: "article/giveALike/web/saveUserGiveALike",
        method: "post",
        data: giveALike
    })
}

//查询当前用户的点赞记录
export function getUserGiveALikeList(userId: number) {
    return axios({
        url: "article/giveALike/web/getUserGiveALikeList/" + userId,
        method: "get"
    })
}

//用户收藏
export function saveUserCollect(collect: Collect) {
    return axios({
        url: "article/collect/web/saveUserCollect",
        method: "post",
        data: collect
    })
}

//查询当前用户的收藏记录
export function getUserCollectList(userId: number) {
    return axios({
        url: "article/collect/web/getUserCollectList/" + userId,
        method: "get"
    })
}

//获取文章信息
export function getArticleDetails(id: number) {
    return axios({
        url: "article/articles/web/getArticleDetails/" + id,
        method: "get"
    })
}

//查询当前用户是否点赞或收藏了文章
export function getUserIsLikeOrCollectArticle(articleId: number, userId: number) {
    return axios({
        url: `article/articles/web/getUserIsLikeOrCollectArticle/${articleId}/${userId}`,
        method: "get"
    })
}

//用户发表评论
export function publishComments(comments: CommentsVo) {
    return axios({
        url: "article/comments/web/publishComments",
        method: "post",
        data: comments
    })
}

//根据文章id获取一级和二级评论
export function getFirstAndSecondComments(articleId: number) {
    return axios({
        url: "article/secondComments/web/getFirstAndSecondComments/" + articleId,
        method: "get"
    })
}

//保存二级回复
export function publishSecondComments(secondComments: SecondCommentsParams) {
    return axios({
        url: "article/secondComments/web/publishSecondComments",
        method: "post",
        data: secondComments
    })
}

//评论点赞
export function giveALikeToComments(commentsGiveALike: CommentsGiveALike) {
    return axios({
        url: "article/commentsGiveALike/web/giveALikeToComments",
        method: "post",
        data: commentsGiveALike
    })
}

//根据文章id和用户id查询用户点赞信息
export function selectCommentsGiveALive(articleId: number, userId: number) {
    return axios({
        url: `article/commentsGiveALike/web/selectCommentsGiveALive/${articleId}/${userId}`,
        method: "get"
    })
}

//保存用户浏览文章记录
export function saveUserBrowse(browse: Browse) {
    return axios({
        url: "article/browse/web/saveUserBrowse",
        method: "post",
        data: browse
    })
}

//用户文章推荐
export function userArticleRecommend(userId: number) {
    return axios({
        url: "article/userRecommend/web/userArticleRecommend",
        method: "get",
        params: {
            userId
        }
    })
}

//文章详情页面中文章推荐
export function articleDetailsRecommend(articleId: number) {
    return axios({
        url: "article/userRecommend/web/articleDetailsRecommend/" + articleId,
        method: "get"
    })
}

//获取当前用户发布的文章
export function getUserArticleList(userId: number) {
    return axios({
        url: "article/articles/web/getUserArticleList/" + userId,
        method: "get"
    })
}

//全文检索
export function searchArticle(requestParams: RequestParams) {
    return axios({
        url: '/es/web/searchArticle',
        method: "post",
        data: requestParams
    })
}

//自动补全
export function getSuggestion(key: string) {
    return axios({
        url: '/es/web/article/suggestion/' + key,
        method: "get"
    })
}

//修改文章
export function modifyArticle(article: object) {
    return axios({
        url: "article/articles/web/modifyArticle",
        method: "put",
        data: article
    })
}